layui.use(['carousel', 'form', 'element'], function() {
    var element = layui.element;
    var layer = layui.layer;
    var form = layui.form;
    var exnr = layer.load();
    var params = sdk.getURLVar('call');
    //监听登录选择
    var user = {
        '1': {
            name: '银行用户',
            register: false,
            path: 'zxw/jrjg/bankDbsx/wdxq',
            yjfk: 'zxw/jrjg/bankDbsx/tsgl',
            cpdel: 'mh/app/product/proInfo',
            clName: '#bankJgDel'
        },
        '2': {
            name: '担保公司',
            register: false,
            path: 'zxw/jrjg/dbgsDbsx/auditList',
            cpdel: 'mh/app/v2/pro/getDbjgProductInfoOne',
            clName: '#dbJgDel'
        },
        '3': {
            name: '政府部门',
            path: 'zxw/gov/app/rzxq_rzytfx?tname=rzytfx',
            yjfk: 'zxw/gov/app/tscl?tname=tscl',
            register: false
        },
        '4': {
            name: '企业用户',
            register: true,
            path: 'zxw/company/xq/release_demand',
            yjfk: 'zxw/company/ts/complaint_admin'
        },
        '5': {
            name: '个人用户',
            register: true
        },
        '6': {
            name: '保险用户',
            register: false,
            path: 'zxw/bxjg/wdsp',
            cpdel: 'mh/app/v2/pro/getBxjgProductInfoOne',
            clName: '#bxJgDel'
        },
        '7': {
            name: '金融专员',
            path: 'zxw/jrzy/index/finance_jrzy',
            register: false
        },
        '8': {
            name: '证券用户',
            register: false,
            path: 'zxw/zqjg/wdsp',
            cpdel: 'mh/app/v2/pro/getZqProductInfoViewOne',
            clName: '#zqJgDel'
        },
        '9': {
            name: '投资机构',
            register: false
        }
    };
    if (!params) {
        checkLogin();
    } else {
        firstReq();
    }
    // 首次登录要调用makeLink
    function firstReq() {
        $.ajax({
            type: 'post',
            data: {
                call: params
            },
            url: sdk.companyIp + 'zxw/company/baohan/makeLink',
            success: function(d) {
                checkLogin();
            }
        })
    };

    // 验证checkLogin
    function checkLogin() {
        $.ajax({
            type: 'post',
            url: sdk.companyIp + 'zxw/company/baohan/checkLogin',
            success: function(d) {
                var urlStr =
                    'http://113.238.142.107/jinzhou-servicePlatform/api/forward?comMark=' +
                    d.comMark + '&signstr=' + d.signstr + '&time=' + d.time + '&token=' +
                    d.token;
                $.ajax({
                    type: 'post',
                    url: sdk.companyIp + 'zxw/company/login/getLoginFlag',
                    dataType: 'json',
                    success: function(userinfo) {
                        layer.close(exnr);
                        if (d.isLogin) {
                            $('#iframeBody').attr('src', urlStr);
                            $('#isLogin').removeClass('noShow');
                            $('#noLogin').addClass('noShow');
                            $('.xy-iframe').removeClass('noShow');
                            $('.noLoginIframe').addClass('noShow');
                            sessionStorage.setItem('baohan_info', d.isLogin);
                            if (userinfo.loginFlag == 'true') {
                                $('.bankName').text(userinfo.userName);
                                $('.bankName').attr('data-val', userinfo.userType);
                            }
                        } else {
                            $('.xy-iframe').addClass('noShow');
                            $('.noLoginIframe').removeClass('noShow');
                            if (userinfo.loginFlag == 'true') {
                                $('.bankName').text(userinfo.userName);
                                $('.bankName').attr('data-val', userinfo.userType);
                                $('#isLogin').removeClass('noShow');
                                $('#noLogin').addClass('noShow');
                            } else {
                                $('#isLogin').addClass('noShow');
                                $('#noLogin').removeClass('noShow');
                            }
                            sessionStorage.setItem('baohan_info', "");
                        }
                    },
                    error: function() {
                        layer.close(exnr);
                    }
                })
            },
            error: function() {
                layer.close(exnr);
            }
        })
    }
    // 点击跳转相应产品
    $('.baohan_body').click(function() {
        var type = $(this).attr('data-type');
        if (type == 'bh') {} else {
            window.location.href = "finance_product.html";
        }
    });
    // 跳转到工作台
    $('.bankName').click(function() {
        var typeId = $(this).attr('data-val');
        if (user[typeId]) {
            location.href = sdk.baseIP + user[typeId].path;
        }
    });
    // 签退
    $('.logoutBtn').click(function() {
        var layer = layui.layer;
        layer.confirm('你确定要退出吗?', {
            icon: 0,
            title: '提示'
        }, function(index) {
            layer.close(index);
            sessionStorage.setItem('baohan_info', '');
            location.href = sdk.baseIP + 'zxw/company/login/loginout';
        });
    });
});
